function [res_struct]=get_struct(image, norm_flag_seg,norm_flag_reg, hypo_option, hypo_amount, reg_per_hypo,bw_factor,med_filter)

% This function is the core function of the project - calculate all features of the picture.

% Function Inputs:
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% image - RGB image matrix.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% norm_flag_seg - how to normalize the segment's features.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% norm_flag_reg - how to normalize the region's features.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% hypo_option  -
%           'distance' - dist calculation for hypothesis.
%           'kmeans' - kmeans calculation for hypothesis. 
%           both are using connected components scheme.
%           'segmentation' - calculate hypothesis using coarse segmentation scheme.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% hypo_amount- number of hypothesises for each value in reg_per_hypo.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% reg_per_hypo - array of values indicates the number of regions in  a hypothesis.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

% Function Outputs:
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% res_struct - a structure of all data taken from the image:
%           seg_map - map of segments.
%           seg_indices - cell of indices of each segment.
%           reg_features_cell - cell of regions features' struct taken from calc_features_reg. 
%           the cell is in size of reg_per_hypo, and each cell contain hypo_amount structs.  
%           reg_indices - cell of indices of each region. the size is the size of reg_features_cell.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

% Global Inputs:
% segment_p.sigma
% segment_p.K_th
% segment_p.min_size

global segment_p

%Calculating segmentation
image_gray=rgb2gray(image);
seg_map=segment_image(image_gray,segment_p.sigma,segment_p.K_th,segment_p.min_size);

% calculating filters for texture features
filters = gaborconvolve(image_gray,4,6,3,2,0.65,1.5,1);
for i=1:size(filters,1)
    for j=1:size(filters,2)
        filters{i,j}=abs(filters{i,j});
    end
end

% Calculating features on segment map
lines=img2lines(image_gray);
HSV=rgb2hsv(image);
[seg_features_struct]=calc_features_seg(image,HSV,seg_map, filters, norm_flag_seg);
num_of_hypo_groups=size(reg_per_hypo,2);
num_hypo=num_of_hypo_groups*hypo_amount;
h = waitbar(0,'Please wait... Calculating Region Features');

% Creating hypothesises using the connected components scheme
if (strcmp(hypo_option,'segmentation')==0)
    [hypothesises,reg_features_cell,reg_indices_cell] = deal(cell(num_of_hypo_groups,1));
    for i=1:num_of_hypo_groups
        % creating hypothesises
        [hypothesises{i}]=create_region_hypothesis(hypo_amount,reg_per_hypo(i),seg_features_struct,hypo_option); 
        [reg_features_cell{i},reg_indices_cell{i}] = deal(cell(hypo_amount,1));                        
        for k = 1:hypo_amount
            count_hypo=(i-1)*hypo_amount+k;
            waitbar(count_hypo/num_hypo);
            one_hypothesis=hypothesises{i}(k,:);
            % making a region map and calculating features
            [reg_map,reg_indices_cell{i}{k}] = reg_vector2reg_map(size(seg_map),one_hypothesis,seg_features_struct.seg_indices,bw_factor,med_filter);
            [reg_features_cell{i}{k}]=calc_features_reg(image,HSV,seg_map,reg_map,filters, norm_flag_reg,reg_indices_cell{i}{k},lines);
         end 
    end 
end

% Creating hypothesises using the coarse segmentation scheme
if (strcmp(hypo_option,'segmentation'))
    [reg_features_cell,reg_indices_cell] = deal(cell(num_of_hypo_groups,1));
    for i=1:num_of_hypo_groups
        % creating hypothesises
        [reg_features_cell{i},reg_indices_cell{i}] = deal(cell(hypo_amount,1));                        
        for k = 1:hypo_amount
            count_hypo=(i-1)*hypo_amount+k;
            waitbar(count_hypo/num_hypo);
            % making a region map and calculating features
            [reg_map,reg_indices_cell{i}{k}] = create_segmentation_hypothesis(image_gray,i,k,num_of_hypo_groups,hypo_amount);
            [reg_features_cell{i}{k}]=calc_features_reg(image,HSV,seg_map,reg_map,filters, norm_flag_reg,reg_indices_cell{i}{k},lines);
         end 
    end 
end

clear filters;
close (h);
res_struct = struct('seg_map',seg_map, 'seg_indices',{seg_features_struct.seg_indices},'reg_features_cell',{reg_features_cell},'reg_indices',{reg_indices_cell});
